package com.heima.admin.controller.v1;

import com.baomidou.mybatisplus.extension.api.R;
import com.heima.admin.service.AdChannelService;
import com.heima.common.exception.CustException;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.dtos.ChannelDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value = "频道管理", tags = "channel", description = "频道管理API")
@RequestMapping("/api/v1/channel")
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;


    @ApiOperation("频道分页列表查询")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ChannelDto dto) {

        return adChannelService.findByNameAndPage(dto);
    }

    @ApiOperation("频道新增")
    @PostMapping("/save")
    public ResponseResult insert(@RequestBody AdChannel channel) {
        return adChannelService.insert(channel);
    }

    @ApiOperation("根据频道ID删除")
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
      /*  if (true) {
            CustException.cust(AppHttpCodeEnum.DATA_NOT_EXIST);
        }*/
        return adChannelService.deleteById(id);
    }

    @ApiOperation("频道修改")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @ApiOperation("查询所有频道的数据")
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<AdChannel> list= adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
